﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using JM.JCY.BusinessEntity.DSJCYD94;
using System.Data;
using JM.JCY.Proxy;

namespace JM.JCY.SharePointComponent.CaseManagement.CaseWarningforNotification
{
    public partial class CaseWarningforNotificationUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GridViewDataBind();
            }
        }

        protected void gvCaseWarning_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvCaseWarning.PageIndex = e.NewPageIndex;
            GridViewDataBind();
        }

        private void GridViewDataBind()
        {
            using (DSJCYD94Proxy proxy = new DSJCYD94Proxy())
            {

                string startDate = "1900-01-01";
                string endDate = "8900-01-01";

                string CBR = SPContext.Current.Web.CurrentUser.Name;
            
                T_AJGL_AJJK_YJAJDataSet.T_AJGL_AJJK_YJAJDataTable dt = proxy.GetAJGL_AJJK_YJAJ(CBR, string.Empty, 0, 0, startDate, endDate);
                if (dt.Rows.Count > 0)
                    this.NoRecord.Visible = false;
                else
                    this.NoRecord.Visible = true;

                foreach (var item in dt)
                {
                    item.N_CQTS = (DateTime.Now.Date - item.D_DQRQ.Date).Days.ToString();
                    item.AcceptChanges();
                }

                DataView dv = dt.DefaultView;
                DataTable dtDis = dv.ToTable(true, "C_AH", "C_CBBM", "C_CBR", "C_AJJD", "C_DQJD", "D_KSRQ", "D_DQRQ", "N_CQTS", "C_XYR", "C_XYRAY");

                this.gvCaseWarning.DataSource = dtDis;
                this.gvCaseWarning.DataBind();
            }
        }

        protected void gvCaseWarning_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int count = Int32.Parse(e.Row.Cells[7].Text);

                if (count > 0)
                {
                    for (int i = 0; i < e.Row.Cells.Count; i++)
                    {
                        e.Row.Cells[i].ControlStyle.ForeColor = System.Drawing.Color.Red;
                    }
                }
                if (count < 1 && count > -6)
                {
                    for (int i = 0; i < e.Row.Cells.Count; i++)
                    {
                        e.Row.Cells[i].ControlStyle.ForeColor = System.Drawing.Color.Yellow;
                    }
                }

            }
        }
    }
}
